[gcode_macro M204]                                                              # Set Acceleration
# Klipper accepts M204 S<value> OR M204 P<value> T<value> where both P and T must be specified
# PrusaSliser sends M204 P<value> without T and Klipper shows an error
# This macro makes M204 command more versatile
description: Set default acceleration
rename_existing: M204.1
gcode:
    {% set factor = params.F|default(0.5)|float %}
    {% if 'S' in params %}
        {% set s = params.S|float %}
        SET_VELOCITY_LIMIT ACCEL={ s } ACCEL_TO_DECEL={ s|float * factor }
    {% else %}
        {% if 'P' in params %}
            {% set p = params.P|float %}
            {% if 'T' in params %}
                {% set t = params.T|float %}
                {% if p < t %}
                    SET_VELOCITY_LIMIT ACCEL={ p } ACCEL_TO_DECEL={ p * factor }
                {% else %}
                    SET_VELOCITY_LIMIT ACCEL={ t } ACCEL_TO_DECEL={ t * factor }
                {% endif %}
            {% else %}
                SET_VELOCITY_LIMIT ACCEL={ p } ACCEL_TO_DECEL={ p * factor }
            {% endif %}
        {% elif 'T' in params %}
            {% set t = params.T|float %}
            SET_VELOCITY_LIMIT ACCEL={ t } ACCEL_TO_DECEL={ t * factor }
        {% endif %}
    {% endif %}
